# -*- coding: utf-8 -*-
"""
@Author : xh
@Time   : 2023/10/29 18:24
"""
from mathsolver.functions.fushu.FuShu_TemplateSolveEngine import fs_template_solve_engine
import logging

logger = logging.getLogger(__name__)
logging.basicConfig(format='%(asctime)s - %(levelname)s: %(message)s', level=logging.DEBUG)


def auto_solver(raw):
    result = {"code": 1, "result": {"steps": [], "answer": ""}}
    template_id = raw.get('template_id', '')
    try:
        if template_id.find('AHFS') >= 0:
            flag, steps, answer = fs_template_solve_engine(raw)
            if flag == 0:
                result["code"] = 0
                result["result"]["steps"] = steps
                result["result"]["answer"] = answer
            else:
                result["code"] = flag
        else:
            result["code"] = -1
    except Exception as E:
        logger.info('[BUG] %s ' % str(E))
        result["code"] = -99
    return result


if __name__ == '__main__':
    a = {
        "question_text": "24215421352315421321",
        "template_id": "AHFS0007",
        "params": {
            "condition": ["复数z = \\frac{1 - ai}{1 + i}(a ∈R)的虚部为-3"],
            "answer_definitions": ["z"],
            "require_answers": ["modulus"]
        }
    }
    _ = auto_solver(a)
    print(_)
